import { computed } from "vue"
import store from "../store"

export const deepCopy = (oldData) => {
  let newData
  // 遍历传进来的数据
  for (let k in oldData) {
    // 将属性值给到 item
    const item = oldData[k]
    // 判断属性是否为 数组 或 对象
    if (item instanceof Array || item instanceof Object) {
      newData[k] = deepCopy(item)
    }
    // 如果不是 数组 或 对象, 直接赋值
    newData[k] = item
  }

  return newData
}

let catesList = computed(() => {
  return store.state.articleCates
}) || []
export const formattingCates = (value) => {
  return catesList.value.find((item) => {
    return item.id === value
  }).name
}